package action;

import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

import service.service_admin.Service_Admin;
import service.service_public.Service_Public;
import service.service_search.Service_Search;
import tools.InterfaceDepthIceList;
import tools.InterfacePropertyIceList;
import tools.InterfaceStationIceList;
import tools.PageBeanPlus;
import entitybean.l_sequence.EntityBeanL_Sequence;
import entitybean.oc_depthlist_ice.EntityBeanOc_Depthlist_Ice;
import entitybean.oc_property_ice.EntityBean_Oc_Property_Ice;
import entitybean.oc_station_ice.EntityBeanOc_Station_Ice;
import form.DepthIceForm;
import form.PropertyIceForm;
import form.StationIcForm;

public class Action_Oc_Property_Ice extends DispatchAction{
	private Service_Admin service_admin;
    private Service_Public service_public;
 	private Service_Search service_search;
	public ActionForward admin_init_oc_property_ice(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		PropertyIceForm actionForm = (PropertyIceForm) form;
		actionForm.setCurrentpage("1");
		actionForm.setKind_id(0);
		actionForm.setProperty_name("");
		actionForm.setOver_time("");
		actionForm.setStart_time("");
		String sql = "select id,property_name,kind_id  from oc_property_ice where del='OFF' ORDER BY id DESC";
		PageBeanPlus pagebeanplus = new PageBeanPlus("oracle", "sql", sql,
				Integer.valueOf(actionForm.getRowcountperpage()), Integer
						.valueOf(actionForm.getCurrentpage()),
				"loadrichtext()");
		InterfacePropertyIceList interfaceforresultsettolist = new InterfacePropertyIceList();
		List<EntityBean_Oc_Property_Ice> list = interfaceforresultsettolist.ViewOc_News(pagebeanplus.getFormatqueryresultset());

		request.setAttribute("pagebeanplus", pagebeanplus);
		request.setAttribute("list", list);
		request.setAttribute("newslistform", actionForm);
		System.out.println("list.size()" + list.size());
		return mapping.findForward("success");
	}

	public ActionForward admin_load_oc_property_ice(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		return null;
	}

	public ActionForward admin_add_oc_property_ice(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		return mapping.findForward("success");
	}

	public ActionForward admin_insert_oc_property_ice(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		PropertyIceForm actionForm = (PropertyIceForm) form;
		Integer kind_id=actionForm.getKind_id();
		String property_name=actionForm.getProperty_name();
		actionForm.setProperty_name("");
		EntityBean_Oc_Property_Ice link=new EntityBean_Oc_Property_Ice();
        link.setKind_id(6);
        link.setProperty_name(property_name);
		link.setDel("OFF");
		Integer i=0;
		EntityBeanL_Sequence entity=new EntityBeanL_Sequence();
		entity=this.service_public.Find_L_Sequence_By_seq_Name("SEQ_OC_PERPERY_ICE");
		i=entity.getSeq_Value()+1;
		entity.setSeq_Value(i);
		link.setId(i);
		this.service_public.Update_L_Sequence(entity);
		this.service_search.Insert_Oc_Property_Ice(link);
		System.out.println("初始化新闻模块");
		// 封装新闻查询的数据及表单
		PropertyIceForm goodForm = (PropertyIceForm) form;
		goodForm.setCurrentpage("1");
		goodForm.setProperty_name("");
		goodForm.setOver_time("");
		goodForm.setStart_time("");
		String sql = "select id,property_name,kind_id  from oc_property_ice where del='OFF' ORDER BY id DESC";
		PageBeanPlus pagebeanplus = new PageBeanPlus("oracle", "sql", sql,
				Integer.valueOf(actionForm.getRowcountperpage()), Integer
						.valueOf(actionForm.getCurrentpage()),
				"loadrichtext()");
		InterfacePropertyIceList interfaceforresultsettolist = new InterfacePropertyIceList();
		List<EntityBean_Oc_Property_Ice> list = interfaceforresultsettolist.ViewOc_News(pagebeanplus.getFormatqueryresultset());


		request.setAttribute("pagebeanplus", pagebeanplus);// 设置传递到页面的数据
		request.setAttribute("list", list);
		request.setAttribute("newslistform", goodForm);
		return mapping.findForward("success");
	}

	public ActionForward admin_delete_oc_property_ice(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		PropertyIceForm actionForm = (PropertyIceForm) form;
		String id = actionForm.getId();
		id = this.cut_tail(id);
		this.service_search.Delete_Oc_Property_Ice(id);

		String sql = "select id,property_name,kind_id  from oc_property_ice where del='OFF' ORDER BY id DESC";
		PageBeanPlus pagebeanplus = new PageBeanPlus("oracle", "sql", sql,
				Integer.valueOf(actionForm.getRowcountperpage()), Integer
						.valueOf(actionForm.getCurrentpage()),
				"loadrichtext()");
		InterfacePropertyIceList interfaceforresultsettolist = new InterfacePropertyIceList();
		List<EntityBean_Oc_Property_Ice> list = interfaceforresultsettolist.ViewOc_News(pagebeanplus.getFormatqueryresultset());

		request.setAttribute("pagebeanplus", pagebeanplus);// 设置传递到页面的数据
		request.setAttribute("list", list);
		request.setAttribute("newslistform", actionForm);
		System.out.println("list.size()" + list.size());
		return mapping.findForward("success");
	}

	public ActionForward admin_update_init_oc_property_ice(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		PropertyIceForm actionForm = (PropertyIceForm) form;
		String id=actionForm.getId();
		EntityBean_Oc_Property_Ice link=this.service_search.Find_EntityBean_Oc_Property_Ice(Integer.valueOf(id));
		request.setAttribute("PlaceView" , link); 
		return mapping.findForward("success");
	}

	public ActionForward admin_update_oc_property_ice(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		PropertyIceForm actionForm = (PropertyIceForm) form;
		String property_name=actionForm.getProperty_name();
		String id=actionForm.getId();
		EntityBean_Oc_Property_Ice link=new EntityBean_Oc_Property_Ice();
		link.setKind_id(6);
		link.setProperty_name(property_name);
		link.setDel("OFF");
		link.setId(Integer.valueOf(id));
		this.service_search.Update_Oc_Property_Ice(link);
		PropertyIceForm goodForm = (PropertyIceForm) form;
		goodForm.setCurrentpage("1");
		goodForm.setProperty_name("");
		goodForm.setOver_time("");
		goodForm.setStart_time("");
		String sql = "select id,property_name,kind_id  from oc_property_ice where del='OFF' ORDER BY id DESC";
		PageBeanPlus pagebeanplus = new PageBeanPlus("oracle", "sql", sql,
				Integer.valueOf(actionForm.getRowcountperpage()), Integer
						.valueOf(actionForm.getCurrentpage()),
				"loadrichtext()");
		InterfacePropertyIceList interfaceforresultsettolist = new InterfacePropertyIceList();
		List<EntityBean_Oc_Property_Ice> list = interfaceforresultsettolist.ViewOc_News(pagebeanplus.getFormatqueryresultset());

		request.setAttribute("pagebeanplus", pagebeanplus);// 设置传递到页面的数据
		request.setAttribute("list", list);
		request.setAttribute("newslistform", goodForm);
	    return mapping.findForward("success");
	}
	public ActionForward admin_search_oc_property_ice(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		PropertyIceForm actionForm = (PropertyIceForm) form;
		String sql = "select id,property_name,kind_id  from oc_property_ice where del='OFF' ORDER BY id DESC";
		PageBeanPlus pagebeanplus = new PageBeanPlus("oracle", "sql", sql,
				Integer.valueOf(actionForm.getRowcountperpage()), Integer
						.valueOf(actionForm.getCurrentpage()),
				"loadrichtext()");
		InterfacePropertyIceList interfaceforresultsettolist = new InterfacePropertyIceList();
		List<EntityBean_Oc_Property_Ice> list = interfaceforresultsettolist.ViewOc_News(pagebeanplus.getFormatqueryresultset());
		
		request.setAttribute("pagebeanplus", pagebeanplus);//设置传递到页面的数据
		request.setAttribute("list", list);
		request.setAttribute("newslistform", actionForm);
		System.out.println("list.size()"+list.size());
		return mapping.findForward("success");
	}
	private String cut_tail(String str) {
		String cut = str;
		if (str.endsWith(",")) {
			cut = cut.substring(0, cut.length() - 1);
		}
		return cut;
	}

	public Service_Admin getService_admin() {
		return service_admin;
	}

	public void setService_admin(Service_Admin service_admin) {
		this.service_admin = service_admin;
	}

	public Service_Public getService_public() {
		return service_public;
	}

	public void setService_public(Service_Public service_public) {
		this.service_public = service_public;
	}

	public Service_Search getService_search() {
		return service_search;
	}

	public void setService_search(Service_Search service_search) {
		this.service_search = service_search;
	}
}
